/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nio;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author zztbak01
 */
public class Client extends Thread{
	private static int port = 9999;
//	public static void main(String[] args) {
//		Client client = new Client();
//		client.start();
//		Scanner systemIn = new Scanner(System.in);
//		while(true){
//			try {
//				String line = systemIn.nextLine();
//				client.bos.write((line+"\n").getBytes());
//				client.bos.flush();
//			} catch (IOException ex) {
//				Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
//			}
//		}
//	}
	Socket socket;
	Scanner scanner;
	BufferedOutputStream bos;
	public Client() {
		try {
			socket = new Socket("localhost", port);
			scanner = new Scanner(socket.getInputStream());
			bos = new BufferedOutputStream(socket.getOutputStream());
		} catch (UnknownHostException ex) {
			Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
		} catch (IOException ex) {
			Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
		}
	}

	@Override
	public void run() {
		while(scanner.hasNext()){
			if(scanner.hasNextLine())
				System.out.println(scanner.nextLine());
			else{
				if(scanner.hasNextByte()){
					System.out.println(scanner.nextByte());
				}
			}
		}
	}

}
